package com.ysw.rpc.client.config;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.cloud.nacos.registry.NacosServiceRegistry;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.cloud.client.serviceregistry.Registration;

/**
 * @author YinShangwen
 * @since 2023/4/18 11:47
 */
public abstract class AbstractClientInitializerConfig extends NacosServiceRegistry implements DisposableBean {

    public AbstractClientInitializerConfig(NacosServiceManager nacosServiceManager, NacosDiscoveryProperties nacosDiscoveryProperties) {
        super(nacosServiceManager, nacosDiscoveryProperties);
    }

    /**
     * 初始化客户端
     */
    public abstract void init();

    /**
     * 该类销毁的时候做的一些处理
     */
    public abstract void destroyHandler();

    @Override
    public void register(Registration registration) {
        super.register(registration);
        init();
    }

    @Override
    public void destroy() {
        destroyHandler();
    }
}
